--	FOM TTT

if SERVER then

   AddCSLuaFile( "shared.lua" )
end

SWEP.HoldType			= "rpg"


if CLIENT then

   SWEP.PrintName			= "RPG"
   SWEP.Slot				= 2

end


SWEP.Base				= "weapon_sigma_base"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModelFlip = false

SWEP.Kind = WEAPON_HEAVY
SWEP.WeaponID = AMMO_M16

SWEP.Primary.Delay			= 2
SWEP.Primary.Recoil			= 1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "rpg_round"
SWEP.Primary.Damage = 1
SWEP.Primary.Cone = 1
SWEP.Primary.ClipSize = 1
SWEP.Primary.ClipMax = 60
SWEP.Primary.DefaultClip = 1
SWEP.AutoSpawnable      = true
SWEP.ViewModel			= "models/weapons/v_rpg.mdl"
SWEP.WorldModel			= "models/weapons/w_rocket_launcher.mdl"

SWEP.Primary.Sound = Sound( "weapons/rpg/rocketfire1.wav" )

SWEP.IronSightsPos 		= Vector( 6, 0, 0.95 )
SWEP.IronSightsAng 		= Vector( 2.6, 1.37, 3.5 )


function SWEP:SetZoom(state)
   if CLIENT then return end
   if state then
      self.Owner:SetFOV(35, 0.5)
   else
      self.Owner:SetFOV(0, 0.2)
   end
end

-- Add some zoom to ironsights for this gun
function SWEP:SecondaryAttack()
   if not self.IronSightsPos then return end
   if self.Weapon:GetNextSecondaryFire() > CurTime() then return end

   bIronsights = not self:GetIronsights()

   self:SetIronsights( bIronsights )

   if SERVER then
      self:SetZoom(bIronsights)
   end

   self.Weapon:SetNextSecondaryFire(CurTime() + 0.3)
end

function SWEP:ShootBullet( dmg, recoil, numbul, cone )

   self.Weapon:SendWeaponAnim(self.PrimaryAnim)

   self.Owner:MuzzleFlash()
   self.Owner:SetAnimation( PLAYER_ATTACK1 )

   if not IsFirstTimePredicted() then return end

   local sights = self:GetIronsights()

local ply = self.Owner
	local aim = self.Owner:GetAimVector()
	local side = aim:Cross(Vector(0,0,1))
	local up = side:Cross(aim)
		if ply:Crouching() then
	up = side:Cross(aim) / 100
	end
	local effectPos = (self.Owner:GetShootPos() +  aim * 100 + side * 8 + up * -15)
	
if SERVER then
	local ply = self.Weapon:GetOwner()
		local vShootPos = self.Owner:GetPos()
		local vShootAng = self.Owner:GetAngles()
		local ent = ents.Create( "proj_rocket" )
			ent:SetPos(self.Owner:GetShootPos())
			ent:Spawn()
			ent:SetOwner(ply)
			ent:SetAngles(vShootAng)
			ent:GetPhysicsObject():SetMass( 250 )
			ent:GetPhysicsObject():SetVelocity( (self:GetForward() * 2800))
			ent:GetPhysicsObject():EnableGravity( false )
			end

   if (not IsValid(self.Owner)) or (not self.Owner:Alive()) or self.Owner:IsNPC() then return end

   if ((game.SinglePlayer() and SERVER) or
       ((not game.SinglePlayer()) and CLIENT and IsFirstTimePredicted())) then

      recoil = sights and (recoil * 0.6) or recoil

      local eyeang = self.Owner:EyeAngles()
      eyeang.pitch = eyeang.pitch - recoil
      self.Owner:SetEyeAngles( eyeang )
   end

end

function SWEP:PreDrop()
   self:SetZoom(false)
   self:SetIronsights(false)
   return self.BaseClass.PreDrop(self)
end

function SWEP:Reload()
   self.Weapon:DefaultReload( ACT_VM_RELOAD );
  		self.Weapon:SetNextPrimaryFire(CurTime() + 2)
   self:SetIronsights( false )
   self:SetZoom(false)
end


function SWEP:Holster()
   self:SetIronsights(false)
   self:SetZoom(false)
   return true
end


